import Vue from "vue";
import VueRouter from "vue-router";
import Index from "../components/LayoutPage.vue";

import { getToken } from "@/utils/auth";
// import Login from "@/views/login.vue";
// import reLogin from "@/views/components/User/relogin.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Index",
    component: Index,
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/components/Login.vue"),
  },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  let token = getToken()

  if (!token) {
    if (to.path !== '/login') {
      next({
        path: '/login',
      })
    } else {
      next()
    }
  } else {
    next()
  }
});

export default router;
